#include "../netfwd.h"

int32_t main( int32_t argc, char * argv[] )
{
	ifaddrs * ifa = NULL;
	int32_t ret = getifaddrs( &ifa );
	if( ret < 0 )
	{
		fprintf( stderr, "error reaseon[%s]\n", strerror( errno ) );
		return -1;
	}
	
	for( ifaddrs * ifp = ifa; ifp != NULL; ifp = ifp->ifa_next )
	{
		if( NULL == ifp->ifa_addr )
			continue;
		char ip[16] = {0};
		memset( ip, 0, 16 );
		strcpy( ip, inet_ntoa(((struct sockaddr_in*)(ifp->ifa_addr))->sin_addr) );
		if( ifp->ifa_netmask )
		{
			char mask[16] = {0};
			strcpy( mask, inet_ntoa(((struct sockaddr_in*)(ifp->ifa_netmask))->sin_addr) );
			fprintf( stdout, "interface name[%s] family[%d] ip[%s] mask[%s]\n", 
				ifp->ifa_name, ifp->ifa_addr->sa_family, ip, mask );
		}
		else
			fprintf( stdout, "interface name[%s] family[%d] ip[%s] mask[]\n", 
				ifp->ifa_name, ifp->ifa_addr->sa_family, ip );			
	}
	
	freeifaddrs( ifa );
	return 0;
}
